home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / basic / pbtool.exe / DBASE.TXT < prev    next >
Text File  |  1992-04-20  |  4KB  |  79 lines

  1. '  filename: DBASE.TXT  author: ANDY KELLETT  date: February 1992
  2. '
  3. '  This file is provided "as-is" to help programmers write code to
  4. '  read/write/view dBASE .DBF files.  This information was used to
  5. '  create programs which I have tested and actually work.  For more
  6. '  information, see the sources at the end of this document. -Thanks
  7. '----------------------------------------------------------
  8.         DBASE.TXT  - Layout of dBASE .DBF files for Programmers
  9.                          dBASE (TM) Ashton-Tate
  10.  
  11.         byte     description
  12.          1        dBASE version, value of 3 w/o a .DBT file,
  13.                   value of 131 with a .DBT file
  14.          2        year   of last update to the file
  15.          3        month    "         "           "
  16.          4        day      "         "           "
  17.          5-8      total number of records in file
  18.          9-10     number of bytes in header (end of header marked by a
  19.                   byte value of 13)
  20.          11-12    individual record length
  21.          13-32    reserved 20 bytes (for multiuser dBASE ??)
  22.  
  23.         The following PowerBasic code will map the entire header into
  24.         HEADER$$ for you:
  25.  
  26.         MAP HEADER$$ * 32, 1 AS VERSION$$, 1 AS YEAR$$, 1 AS MONTH$$,_
  27.            1 AS DAY$$, 4 AS TOT.RECORDS$$, 2 AS HEADER.SIZE$$,_
  28.            2 AS RECORD.LENGTH$$, 20 AS FILLER$$
  29.  
  30.         The two byte fields contain numbers in low-byte/high-byte format
  31.         common in Intel processors.  If the values 05 02 were present,
  32.         the actual value would be: 05 + (256 * 02) = 517
  33.  
  34.         The four byte field for total number of records is handled a
  35.         bit differently.  If the hexadecimal values were 0F C1 01 00
  36.         then the actual value would be:  00 01 C1 0F .
  37.  
  38.  
  39.         Following the file header are individual 32 byte headers for each
  40.         field.  You will need to use the (number of bytes in the header)
  41.         from the file header to calculate how many fields there are.  It
  42.         will then be a matter of looping to read each individual field
  43.         header and storing it one at a time.
  44.  
  45.         byte     description
  46.          10       Field name, padded with CHR$(0) if needed
  47.           1       filler (always 0 ??)
  48.           1       Field type (Character, Numeric, Logical, Memo, Date)
  49.           4       filler (used for data address in RAM while in memory)
  50.           1       Field width
  51.           1       Number of decimal places ( CHR$(0) if not numeric type)
  52.          14       reserved
  53.  
  54.         The following PowerBasic code will map the entry for a single
  55.         dBASE field into FIELDHEADER$$ for you:
  56.  
  57.         MAP FIELDHEADER$$ * 32, 10 AS FIELD.NAME$$, 1 AS FILLER1$$, _
  58.            1 AS FIELD.TYPE$$, 4 AS FILLER2$$, 1 AS FIELD.WIDTH$$,_
  59.            1 AS DECIMALS$$, 14 AS FILLER3$$
  60.  
  61.         Once you've split FIELDHEADER$$ into its individual fields, you
  62.         can move them into a table (for example) to easily handle .DBF
  63.         files with many fields.
  64.  
  65. '----------------------------------------------------------
  66. '   Information on the structure of dBASE .DBF files were
  67. '         obtained from the following two sources:
  68. '
  69. '   dBASE III Plus Programmer's Reference Guide  pp.859 - 875
  70. '   by Alan Simpson ( 1987 SYBEX Inc.)  No dBASE programmer
  71. '   should ever be more than arms-length away from this book.
  72. '
  73. '   BASIC Techniques and Utilities p. 251  by Ethan Winer
  74. '   ( 1991 Ziff-Davis Press ).  Never thought about reading dBASE
  75. '   files from Turbo/PowerBasic until I stumbled over his
  76. '   easy-to-understand chapter.  Did not use his code as a model.
  77. '
  78. '
  79.